package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Resource
    private DishService dishService;
    @GetMapping("/page")
    @ApiOperation(value = "菜品分类查询")
    public Result SelectedDishPageQuery(DishPageQueryDTO dishPageQueryDTO) {
     PageResult result = dishService.SelectedDishPageQuery(dishPageQueryDTO);
     return Result.success(result);
    }
    //修改菜品
    @PutMapping
    @ApiOperation(value = "修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public Result SelectedDishById(@PathVariable Long id){
        DishVO dishVO = dishService.SelectedDishById(id);
        return Result.success(dishVO);
    }
    //根据菜品分类id查询
    @GetMapping("/list")
    @ApiOperation(value = "根据菜品分类id查询")
    public Result SelectedDishByCategoryId(Long categoryId){
       List<Dish> dishList= dishService.SelectedDishByCategoryId(categoryId);
        return Result.success(dishList);
    }
    //修改当前状态
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改当前状态")
    public Result updateStatus(DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }
    //新增菜品
    @PostMapping
    @ApiOperation(value = "新增菜品")
    public Result InsertDish(@RequestBody DishDTO dishDTO){
        dishService.insertDish(dishDTO);
        return Result.success();
    }
    //根据id批量删除
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping
    public Result DeleteDish(@RequestParam("ids") List<Long> ids){
        dishService.deleteDishById(ids);
        return Result.success();
    }
}
